$(function () {
        FastClick.attach(document.body);
     $(".spinner").show();
    $.ajax({
        type: "post",
        url: "http://www.jzxchina.cn/M_AjaxData/M_PatientInfoAjax/GetTimeLine",
        data: {"IdCard": "430725198909253977"},
        dataType: "JSONP",
        success: function (data) {
            console.log(data);
            $('#length').text(data.length);
            var yearNum = [];
            $(data).each(function(i, v){
                yearNum.push(this.dPatientHInDate.substring(0,4));
            })
            var years = {};

            for (var i = 0; i < yearNum.length; i++){
                if(!years[yearNum[i]]) {
                    years[yearNum[i] + ''] = [];
                }
            };

            $(data).each(function(i, v){
                for (var j in years) {
                    if(v.dPatientHInDate.substring(0,4) == j){
                        years[v.dPatientHInDate.substring(0,4)].push(v);
                        break;
                    }
                }
            });
            for (var k in years) {
                var html = template("tp", {item: years[k]});
                $(".Hospital-timeBase").prepend(html);
            }
            console.log(years);
            $('.zz').each(function (i, v) {
                $(v).click(function () {
                    $(this).attr("href","historySheet.html?index=" + JSON.stringify(data[i]));
                })
            });
            //异常数据
            $(".spinner").show();
           $(".Hospital-Disease-l").each(function (i,v) {
               $(this).on("click",function () {
                var serial=$(this).data("num");
                   $.ajax({
                       type:"get",
                       url:"http://www.jzxchina.cn/M_AjaxData/M_PatientInfoAjax/GetAbnormalValue",
                       data: {"sPatientHGuid": serial},
                       dataType: "JSONP",
                       success:function (data) {
                           console.log(data);
                            $("#Hospital-length").html(data.length);
                           if(data.length==0){
                           	    $(".Hospital-list>ul").html("");
                               $(".Hospital-list>p").text("您的健康良好");
                           }else {
                  			   $(".Hospital-list>p").text("");
                             
                               for(var i=0; i<data.length;i++){
                                   if(data[i].iAbnormal<=2){
                                       data[i].sCollectionBillValue=parseFloat(data[i].sCollectionBillValue).toString();
                                   }
                               };
                               var html=template("serial",{"item":data});
                               $(".Hospital-list>ul").html(html);
                               $(".l-abnormal").each(function (i,v) {
                                   if($(v).data("change")==1){
                                   };
                                   if($(v).data("change")==2){
                                       $(this).find("img").css({"transform":"rotate(180deg)","margin-top":"-.08rem"})
                                   };
                                   if($(v).data("change")==3){
                                       $(this).find("img").remove();
                                   }
                               });
                           }
                           $(".spinner").hide();
                       }
                   })
               })
           });
            $(".Hospital-timeBase>ul:first-of-type .show").addClass("active");
            $(".spinner").hide();
        }

    });
        var witdth= $(window).width();

    //切换时间轴
    $('.Hospital-timeBase').on('click', '.show', function () {
        if ($(this).hasClass("active")) {
            $(this).parent().next().slideUp(500);
        } else {
            $(this).parent().next().slideDown(500);
        };
        $(this).toggleClass("active")
    });
})